package com.punai.customer.controller;

import com.punai.common.annotation.Log;
import com.punai.common.core.controller.BaseController;
import com.punai.common.core.domain.AjaxResult;
import com.punai.common.core.page.TableDataInfo;
import com.punai.common.enums.BusinessType;
import com.punai.customer.domain.CusMaterialCuChapter;
import com.punai.customer.domain.contants.CusConstants;
import com.punai.customer.service.ICusMaterialCuChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 材料章节Controller
 * 
 * @author zxw_
 * @date 2023-01-30
 */
@RestController
@RequestMapping("/cus/cuMaterialChapter")
public class CusMaterialCuChapterController extends BaseController
{
    @Autowired
    private ICusMaterialCuChapterService cusMaterialCuChapterService;

    /**
     * 查询材料章节列表
     */
    @PreAuthorize("@ss.hasPermi('materialChapter:cuMaterialChapter:list')")
    @GetMapping("/list")
    public TableDataInfo list(CusMaterialCuChapter cusMaterialCuChapter)
    {
        startPage();
        List<CusMaterialCuChapter> list = cusMaterialCuChapterService.selectCusMaterialCuChapterList(cusMaterialCuChapter);
        return getDataTable(list);
    }

    /**
     * 获取材料章节详细信息
     */
    @PreAuthorize("@ss.hasPermi('materialChapter:cuMaterialChapter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(cusMaterialCuChapterService.selectCusMaterialCuChapterById(id));
    }

    /**
     * 新增材料章节
     */
    @PreAuthorize("@ss.hasPermi('materialChapter:cuMaterialChapter:add')")
    @Log(title = CusConstants.CL_NAME + "章节", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CusMaterialCuChapter cusMaterialCuChapter)
    {
        return toAjax(cusMaterialCuChapterService.insertCusMaterialCuChapter(cusMaterialCuChapter));
    }

    /**
     * 修改材料章节
     */
    @PreAuthorize("@ss.hasPermi('materialChapter:cuMaterialChapter:edit')")
    @Log(title = CusConstants.CL_NAME + "章节", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CusMaterialCuChapter cusMaterialCuChapter)
    {
        return toAjax(cusMaterialCuChapterService.updateCusMaterialCuChapter(cusMaterialCuChapter));
    }

    /**
     * 删除材料章节
     */
    @PreAuthorize("@ss.hasPermi('materialChapter:cuMaterialChapter:remove')")
    @Log(title = CusConstants.CL_NAME + "章节", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(cusMaterialCuChapterService.deleteCusMaterialCuChapterByIds(ids));
    }
}
